#ifndef TIMER_H
#define TIMER_H

#include "../global.h"
#include <boost/asio/deadline_timer.hpp>
#include <boost/function.hpp>

class Timer : protected boost::noncopyable
{
public:
    typedef boost::asio::io_service IOService;
    typedef boost::asio::deadline_timer Implement;
    typedef boost::system::error_code ErrorCode;

    typedef boost::function< void (int) > Notifier;

public:
    Timer(IOService &service, unsigned int owner, unsigned int id, unsigned long elapse, unsigned int repeat);
    ~Timer();

    void start(BOOST_ASIO_MOVE_ARG(Notifier) n);

    void cancel();

    unsigned int owner() const;

    unsigned int id() const;

    unsigned long elapse() const;

    unsigned int repeat()  const;

protected:
    void onTimerout(Notifier n, const ErrorCode &ec);

protected:
    Implement m_impl;

    unsigned int m_owner;

    unsigned int m_id;

    unsigned long m_elapse;

    unsigned int m_repeat;
};

#endif // TIMER_H
